// index.ts
import { createI18n } from 'vue-i18n'
import zh from './langs/zh'
import en from './langs/en'

const messages = {
  en,
  zh,
}
const urlParams = new URLSearchParams(window.location.search)
const urlLang:string | null = urlParams.get('lan')
// 'zh_hans' || urlLang === 'zh_hant
if (urlLang) {
  if (urlLang === 'en') {
    console.log('英文')
    sessionStorage.setItem('lang', 'en')
  }
  else {
    console.log('中文')
    sessionStorage.setItem('lang', 'zh')
  }
}
else {
  // localStorage.setItem('lang', 'zh')
  sessionStorage.setItem('lang', 'zh')
}
const i18n = createI18n({
  locale: sessionStorage.getItem('lang') || 'zh', // 首先从缓存里拿，没有的话就用浏览器语言，
  // fallbackLocale: 'zh', // 设置备用语言
  fallbackLocale: 'zh',
  messages,
  legacy: false,
  globalInjection: true,
})

export default i18n
